﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;

namespace Expertime.Multitude.Intranet.Security
{
    public static class SecurityUtils
    {
        public static bool IsCurrentUserContributor(SPSecurableObject securableObject)
        {
            return HasCurrentUserRole(securableObject, SPRoleType.Contributor);
        }
        public static bool HasCurrentUserRole(SPSecurableObject securableObject, SPRoleType roleType)
        {
            IEnumerable<SPRoleDefinition> roles = securableObject.AllRolesForCurrentUser.Cast<SPRoleDefinition>();
            // Uniquement pour les types de base: Guest, Reader, Contributor, WebDesigner, Administrator
            SPRoleType maxRole = roles.Select(r => r.Type).Max();
            return maxRole >= roleType;
        }

    }
}
